package web.api.common.controller;

import blue.http.annotation.Http;
import blue.http.annotation.HttpMethod;
import blue.http.message.Request;
import blue.validation.group.SaveModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import web.api.common.model.Token;
import web.api.common.model.User;
import web.core.util.ErrorCode;

/**
 * @author Jin Zheng
 * @since 1.0 2020-08-31
 */
@Controller
@Http(url = "/index")
public class IndexController
{
	private static Logger logger = LoggerFactory.getLogger(IndexController.class);

	public IndexController()
	{
	}

	@Http(url = "/login", method = HttpMethod.POST)
	public Token login(Request request)
	{
		logger.info("user json: {}", request.getContent());
		User user = request.getContentJson(User.class, SaveModel.class);
		if (user.getUsername().equals("admin")
			&& user.getPassword().equals("123456"))
		{
			return new Token();
		}
		throw ErrorCode.LOGIN_FAILURE.newException();
	}

}
